"""
后台管理面板管理配置
"""

from django.contrib import admin
from .models import SystemConfig, OperationLog, AdminPermission


@admin.register(SystemConfig)
class SystemConfigAdmin(admin.ModelAdmin):
    """
    系统配置管理
    """
    
    list_display = ['key', 'config_type', 'is_active', 'created_at', 'updated_at']
    
    list_filter = ['config_type', 'is_active', 'created_at']
    
    search_fields = ['key', 'value', 'description']
    
    ordering = ['config_type', 'key']
    
    fieldsets = (
        ('基本信息', {
            'fields': ('key', 'value', 'config_type')
        }),
        ('配置描述', {
            'fields': ('description',)
        }),
        ('状态设置', {
            'fields': ('is_active',)
        }),
    )


@admin.register(OperationLog)
class OperationLogAdmin(admin.ModelAdmin):
    """
    操作日志管理
    """
    
    list_display = [
        'operator', 'operation_type', 'module', 
        'description', 'ip_address', 'created_at'
    ]
    
    list_filter = ['operation_type', 'module', 'created_at']
    
    search_fields = ['operator__username', 'description', 'ip_address']
    
    ordering = ['-created_at']
    
    readonly_fields = ['operator', 'operation_type', 'module', 'description', 'detail', 'ip_address', 'user_agent', 'created_at']
    
    fieldsets = (
        ('操作信息', {
            'fields': ('operator', 'operation_type', 'module', 'description')
        }),
        ('详细信息', {
            'fields': ('detail', 'ip_address', 'user_agent')
        }),
        ('时间信息', {
            'fields': ('created_at',)
        }),
    )


@admin.register(AdminPermission)
class AdminPermissionAdmin(admin.ModelAdmin):
    """
    管理员权限管理
    """
    
    list_display = ['name', 'code', 'module', 'is_active', 'created_at']
    
    list_filter = ['module', 'is_active', 'created_at']
    
    search_fields = ['name', 'code', 'description']
    
    ordering = ['module', 'name']
    
    fieldsets = (
        ('权限信息', {
            'fields': ('name', 'code', 'module')
        }),
        ('权限描述', {
            'fields': ('description',)
        }),
        ('状态设置', {
            'fields': ('is_active',)
        }),
    )
